CREATE DATABASE CROSSWORD
USE CROSSWORD

IF EXISTS(SELECT * FROM DBO.SYSOBJECTS WHERE NAME='PUZZLE')
BEGIN
DROP TABLE PUZZLE
END
GO
CREATE TABLE PUZZLE
(
	PUZZLEID INTEGER IDENTITY(1,1),
	PUZZLENAME NVARCHAR(30) NOT NULL
	PRIMARY KEY (PUZZLEID)
)

IF EXISTS(SELECT * FROM DBO.SYSOBJECTS WHERE NAME='USERS')
BEGIN
DROP TABLE USERS
END
GO
CREATE TABLE USERS
(
	USERID INTEGER IDENTITY(1,1),
	USERNAME NVARCHAR(40) NOT NULL,
	PASSWORD NVARCHAR(40) NOT NULL
	PRIMARY KEY (USERID)
)

IF EXISTS(SELECT * FROM DBO.SYSOBJECTS WHERE NAME='QUESTIONS')
BEGIN
DROP TABLE QUESTIONS
END
GO
CREATE TABLE QUESTIONS
(
	QUESTIONID INTEGER IDENTITY(1,1),
	DETAIL NVARCHAR(500) NULL,
	PRIMARY KEY (QUESTIONID)
)

IF EXISTS(SELECT * FROM DBO.SYSOBJECTS WHERE NAME='ANSWER4X4')
BEGIN
DROP TABLE ANSWER4X4
END
GO
CREATE TABLE ANSWER4X4
(
	ANSWER4X4ID INT IDENTITY(1,1),
	PUZZLEID INTEGER NOT NULL,
	QUESTIONID INTEGER NOT NULL,
	VALUE1 VARCHAR(1) NOT NULL,
	VALUE2 VARCHAR(1) NOT NULL,
	VALUE3 VARCHAR(1) NOT NULL,
	VALUE4 VARCHAR(1) NOT NULL
	PRIMARY KEY (ANSWER4X4ID)
)

IF EXISTS(SELECT * FROM DBO.SYSOBJECTS WHERE NAME='ANSWER6X6')
BEGIN
DROP TABLE ANSWER6X6
END
GO
CREATE TABLE ANSWER6X6
(
	ANSWER6X6ID INT IDENTITY(1,1),
	PUZZLEID INTEGER NOT NULL,
	QUESTIONID INTEGER NOT NULL,
	VALUE1 VARCHAR(1) NOT NULL,
	VALUE2 VARCHAR(1) NOT NULL,
	VALUE3 VARCHAR(1) NOT NULL,
	VALUE4 VARCHAR(1) NOT NULL,
	VALUE5 VARCHAR(1) NOT NULL,
	VALUE6 VARCHAR(1) NOT NULL
	PRIMARY KEY (ANSWER6X6ID)
)

IF EXISTS(SELECT * FROM DBO.SYSOBJECTS WHERE NAME='HIGHSCORES')
BEGIN
DROP TABLE HIGHSCORES
END
GO
CREATE TABLE HIGHSCORES
(
	HIGHSCOREID INTEGER IDENTITY(1,1),
	TYPE INT NULL,
	PLAYERNAME NVARCHAR(40) NULL,
	SCORES FLOAT NULL,
	TIMES NVARCHAR(5) NULL
	PRIMARY KEY (HIGHSCOREID)
)